package com.xyht.sca_s.student_manage_system.modules.payment.wxpay.controller;

import com.xyht.sca_s.student_manage_system.common.annotation.RequestPass;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonResult;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.modules.payment.wxpay.entity.CallbackBodyEntity;
import com.xyht.sca_s.student_manage_system.modules.payment.wxpay.entity.WxPayCommonConfig;
import com.xyht.sca_s.student_manage_system.modules.payment.wxpay.entity.WxPayConfigProperties;
import com.xyht.sca_s.student_manage_system.modules.payment.wxpay.service.WxService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/wxpay")
public class WxController {
    @Resource
    private WxService wxService;
    @Resource
    private WxPayConfigProperties wxPayConfigProperties;

    @PostMapping("/payCallback")
    @ApiModelProperty("微信支付回调接口")
    @RequestPass
    public String wxPayCallback(@RequestBody CallbackBodyEntity entity, HttpServletRequest request, HttpServletResponse response) {
        return wxService.wxPayCallback(entity,request,response);
    }
    @PostMapping("/payCallbackOne")
    @ApiModelProperty("微信支付回调接口")
    @RequestPass
    public String wxPayCallbackOne(@RequestBody CallbackBodyEntity entity, HttpServletRequest request, HttpServletResponse response) {
        return wxService.wxPayCallbackOne(entity,request,response);
    }
    @PostMapping("/payCallbackTwo")
    @ApiModelProperty("微信支付回调接口")
    @RequestPass
    public String wxPayCallbackTwo(@RequestBody CallbackBodyEntity entity, HttpServletRequest request, HttpServletResponse response) {
        return wxService.wxPayCallbackTwo(entity,request,response);
    }

    @GetMapping("/payStore")
    @ApiModelProperty("收款账号列表")
    @RequestPass
    public ResponseResult payStore() {
        List<Map<String,Object>> list = new ArrayList<>();
        if (wxPayConfigProperties.getConfigs() == null || wxPayConfigProperties.getConfigs().size() < 1){
            return CommonResult.success(list);
        }
        int sort = 1;
        for (WxPayCommonConfig wxPayCommonConfig:wxPayConfigProperties.getConfigs()) {
            HashMap<String,Object> map = new HashMap<>();
            map.put("sort",sort++);
            map.put("name",wxPayCommonConfig.getCONFIG_NAME());
            list.add(map);
        }
        return CommonResult.success(list);
    }



    @PostMapping("/rxRegistrationPayCallback")
    @ApiModelProperty("微信支付回调接口")
    @RequestPass
    public String rxRegistrationPayCallback(@RequestBody CallbackBodyEntity entity, HttpServletRequest request, HttpServletResponse response) {
        return wxService.rxRegistrationPayCallback(entity,request,response);
    }

    @PostMapping("/tsPayCallback")
    @ApiModelProperty("微信支付回调接口")
    @RequestPass
    public String tsPayCallback(@RequestBody CallbackBodyEntity entity, HttpServletRequest request, HttpServletResponse response) {
        return wxService.tsPayCallback(entity,request,response);
    }


}
